﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Text;
namespace HCDV.HCSP
{
    public class SPTableBll
    {

        public DataTable GetPageInfo(int starPage, int pageSize, string Query, out int allrow)
        {
            DataTable table;
            using (dbsimpleold acess = new dbsimpleold())
            {
                table = acess.getPageInfo("Table_SP_GetALL", starPage, pageSize, Query, out allrow);
            }
            return table;
        }
        public DataTable GetPageInfoWf(int starPage, int pageSize, string Query, out int allrow)
        {
            DataTable table;
            using (dbsimpleold acess = new dbsimpleold())
            {
                table = acess.getPageInfo("Table_SP_WfGetALL", starPage, pageSize, Query, out allrow);
            }
            return table;
        }
        /// <summary>
        /// 获取加钞计划表对象
        /// </summary>
        public DataTable GetSPInfo(string ID)
        {
            DataTable table;
            using (dbsimpleold acess = new dbsimpleold())
            {
                table = acess.GetDataSetByID("Table_SP_selectById", ID, "ID").Tables[0];
            }
            return table;
        }
        public bool DeleteSP(string pid)
        {
            bool re;
            using (dbsimpleold acess = new dbsimpleold())
            {
                re = acess.DeleteInfoByID("Table_SP_deleteById", pid, "ID");
            }
            return re;
        }


        /// <summary>
        /// 获取SP对象
        /// </summary>

        public Table_SP GetTable_SP(string ID)
        {
            DataTable table = GetSPInfo(ID);
            Table_SP ret = new Table_SP();
            if (table == null && table.Rows.Count != 1) return null;
            if (table.Rows[0]["id"] != null)
                ret.id = table.Rows[0]["id"].ToString();
            if (table.Rows[0]["type"] != null)
                ret.type = table.Rows[0]["type"].ToString();
            if (table.Rows[0]["typename"] != null)
                ret.typename = table.Rows[0]["typename"].ToString();
            if (table.Rows[0]["mainname"] != null)
                ret.mainname = table.Rows[0]["mainname"].ToString();
            if (table.Rows[0]["maintype"] != null)
                ret.maintype = table.Rows[0]["maintype"].ToString();
            if (table.Rows[0]["fv1"] != null)
                ret.fv1 = table.Rows[0]["fv1"].ToString();
            if (table.Rows[0]["fv2"] != null)
                ret.fv2 = table.Rows[0]["fv2"].ToString();
            if (table.Rows[0]["fv3"] != null)
                ret.fv3 = table.Rows[0]["fv3"].ToString();
            if (table.Rows[0]["fv4"] != null)
                ret.fv4 = table.Rows[0]["fv4"].ToString();
            if (table.Rows[0]["fv5"] != null)
                ret.fv5 = table.Rows[0]["fv5"].ToString();
            if (table.Rows[0]["fv6"] != null)
                ret.fv6 = table.Rows[0]["fv6"].ToString();
            if (table.Rows[0]["fv7"] != null)
                ret.fv7 = table.Rows[0]["fv7"].ToString();
            if (table.Rows[0]["fv8"] != null)
                ret.fv8 = table.Rows[0]["fv8"].ToString();
            if (table.Rows[0]["fv9"] != null)
                ret.fv9 = table.Rows[0]["fv9"].ToString();
            if (table.Rows[0]["fv10"] != null)
                ret.fv10 = table.Rows[0]["fv10"].ToString();

            if (table.Rows[0]["nv1"] != null)
                ret.nv1 = table.Rows[0]["nv1"].ToString();
            if (table.Rows[0]["nv2"] != null)
                ret.nv2 = table.Rows[0]["nv2"].ToString();
            if (table.Rows[0]["nv3"] != null)
                ret.nv3 = table.Rows[0]["nv3"].ToString();
            if (table.Rows[0]["nv4"] != null)
                ret.nv4 = table.Rows[0]["nv4"].ToString();
            if (table.Rows[0]["nv5"] != null)
                ret.nv5 = table.Rows[0]["nv5"].ToString();
            if (table.Rows[0]["nv6"] != null)
                ret.nv6 = table.Rows[0]["nv6"].ToString();
            if (table.Rows[0]["nv7"] != null)
                ret.nv7 = table.Rows[0]["nv7"].ToString();
            if (table.Rows[0]["nv8"] != null)
                ret.nv8 = table.Rows[0]["nv8"].ToString();
            if (table.Rows[0]["nv9"] != null)
                ret.nv9 = table.Rows[0]["nv9"].ToString();
            if (table.Rows[0]["nv10"] != null)
                ret.nv10 = table.Rows[0]["nv10"].ToString();
            if (table.Rows[0]["dt1"] != null)
                ret.dt1 = table.Rows[0]["dt1"].ToString();
            if (table.Rows[0]["dt2"] != null)
                ret.dt2 = table.Rows[0]["dt2"].ToString();
            if (table.Rows[0]["dt3"] != null)
                ret.dt3 = table.Rows[0]["dt3"].ToString();
            if (table.Rows[0]["dt4"] != null)
                ret.dt4 = table.Rows[0]["dt4"].ToString();

            return ret;
        }
        /// <summary>
        /// <summary>
        /// 创建
        /// </summary>
        public bool Create(Table_SP param)
        {
            Fields fs = new Fields();

            fs.AddField("id", param.id, false);
            fs.AddField("type", param.type, false);
            fs.AddField("typename", param.typename, false);
            fs.AddField("mainname", param.mainname, false);
            fs.AddField("maintype", param.maintype, false);
            fs.AddField("fv1", param.fv1, false);
            fs.AddField("fv2", param.fv2, false);
            fs.AddField("fv3", param.fv3, false);
            fs.AddField("fv4", param.fv4, false);
            fs.AddField("fv5", param.fv5, false);
            fs.AddField("fv6", param.fv6, false);
            fs.AddField("fv7", param.fv7, false);
            fs.AddField("fv8", param.fv8, false);
            fs.AddField("fv9", param.fv9, false);
            fs.AddField("fv10", param.fv10, false);
            fs.AddField("nv1", param.nv1, false);
            fs.AddField("nv2", param.nv2, false);
            fs.AddField("nv3", param.nv3, false);
            fs.AddField("nv4", param.nv4, false);
            fs.AddField("nv5", param.nv5, false);
            fs.AddField("nv6", param.nv6, false);
            fs.AddField("nv7", param.nv7, false);
            fs.AddField("nv8", param.nv8, false);
            fs.AddField("nv9", param.nv9, false);
            fs.AddField("nv10", param.nv10, false);
            fs.AddField("dt1", param.dt1, false);
            fs.AddField("dt2", param.dt2, false);
            fs.AddField("dt3", param.dt3, false);
            fs.AddField("dt4", param.dt4, false);
            fs.AddField("adduser", param.adduser, false);
            fs.AddField("wfid", param.wfid, false);
            fs.AddField("fatherid", param.fatherid, false);
            fs.AddField("modelid", param.modelid, false);
            fs.AddField("addorgmain", param.addorgmain, false);
            fs.AddField("addorgthis", param.addorgthis, false);
            fs.AddField("state", param.state, false);
            string lprcname = "Table_SP_insert";

            using (dbsimpleold db = new dbsimpleold())
            {
                return db.InsertTableInfo(lprcname, fs);
            }
        }

        /// <summary>
        /// 修改
        /// </summary>
        /// <param name="param"></param>
        /// <returns></returns>
        public bool Updata(Table_SP param)
        {
            Fields fs = new Fields();

            fs.AddField("id", param.id, false);
            fs.AddField("type", param.type, false);
            fs.AddField("typename", param.typename, false);
            fs.AddField("mainname", param.mainname, false);
            fs.AddField("maintype", param.maintype, false);
            fs.AddField("fv1", param.fv1, false);
            fs.AddField("fv2", param.fv2, false);
            fs.AddField("fv3", param.fv3, false);
            fs.AddField("fv4", param.fv4, false);
            fs.AddField("fv5", param.fv5, false);
            fs.AddField("fv6", param.fv6, false);
            fs.AddField("fv7", param.fv7, false);
            fs.AddField("fv8", param.fv8, false);
            fs.AddField("fv9", param.fv9, false);
            fs.AddField("fv10", param.fv10, false);
            fs.AddField("nv1", param.nv1, false);
            fs.AddField("nv2", param.nv2, false);
            fs.AddField("nv3", param.nv3, false);
            fs.AddField("nv4", param.nv4, false);
            fs.AddField("nv5", param.nv5, false);
            fs.AddField("nv6", param.nv6, false);
            fs.AddField("nv7", param.nv7, false);
            fs.AddField("nv8", param.nv8, false);
            fs.AddField("nv9", param.nv9, false);
            fs.AddField("nv10", param.nv10, false);
            fs.AddField("dt1", param.dt1, false);
            fs.AddField("dt2", param.dt2, false);
            fs.AddField("dt3", param.dt3, false);
            fs.AddField("dt4", param.dt4, false);
            fs.AddField("adduser", param.adduser, false);
            fs.AddField("wfid", param.wfid, false);
            fs.AddField("fatherid", param.fatherid, false);
            fs.AddField("modelid", param.modelid, false);
            fs.AddField("addorgmain", param.addorgmain, false);
            fs.AddField("addorgthis", param.addorgthis, false);
            fs.AddField("state", param.state, false);
            string lprcname = "Table_SP_updateById";


            using (dbsimpleold db = new dbsimpleold())
            {
                return db.InsertTableInfo(lprcname, fs);
            }
        }


        public DataTable GetWFSPInfo(string ID)
        {
            DataTable table;
            using (dbsimpleold acess = new dbsimpleold())
            {
                table = acess.GetDataSetByID("Table_SP_WF_selectById", ID, "ID").Tables[0];
            }
            return table;
        }
    }

    public class Table_SP
    {
        public string id = null;
        public string type = null;
        public string typename = null;
        public string mainname = null;
        public string maintype = null;
        public string fv1 = null;
        public string fv2 = null;
        public string fv3 = null;
        public string fv4 = null;
        public string fv5 = null;
        public string fv6 = null;
        public string fv7 = null;
        public string fv8 = null;
        public string fv9 = null;
        public string fv10 = null;
        public string nv1 = null;
        public string nv2 = null;
        public string nv3 = null;
        public string nv4 = null;
        public string nv5 = null;
        public string nv6 = null;
        public string nv7 = null;
        public string nv8 = null;
        public string nv9 = null;
        public string nv10 = null;
        public string dt1 = null;
        public string dt2 = null;
        public string dt3 = null;
        public string dt4 = null;
        public string adduser = null;
        public string wfid = null;
        public string fatherid = null;
        public string modelid = null;
        public string addorgthis = null;
        public string addorgmain = null;
        public string state = null;

        /// <summary>
        /// 为了加快，可以动态设置这个数组
        /// </summary>
        public string[] fieldsall = { "id", 
                                        "fv1", "fv2", "fv3", "fv4", "fv5", "fv6", "fv7", "fv8", "fv9", "fv10" ,
                                        "nv1", "nv2", "nv3", "nv4", "nv5", "nv6", "nv7", "nv8", "nv9", "nv10" ,
                                        "dt1", "dt2", "dt3", "dt4","adduser","wfid","fatherid","modelid","addorgthis","addorgmain","state"
                                    };
        /// <summary>
        /// 设置值
        /// </summary>
        /// <param name="fname"></param>
        /// <param name="fvalue"></param>
        public void setvalue(string fname, string fvalue)
        {
            switch (fname)
            {
                case "fv1": fv1 = fvalue; break;
                case "fv2": fv2 = fvalue; break;
                case "fv3": fv3 = fvalue; break;
                case "fv4": fv4 = fvalue; break;
                case "fv5": fv5 = fvalue; break;
                case "fv6": fv6 = fvalue; break;
                case "fv7": fv7 = fvalue; break;
                case "fv8": fv8 = fvalue; break;
                case "fv9": fv9 = fvalue; break;
                case "fv10": fv10 = fvalue; break;
                case "nv1": nv1 = fvalue; break;
                case "nv2": nv2 = fvalue; break;
                case "nv3": nv3 = fvalue; break;
                case "nv4": nv4 = fvalue; break;
                case "nv5": nv5 = fvalue; break;
                case "nv6": nv6 = fvalue; break;
                case "nv7": nv7 = fvalue; break;
                case "nv8": nv8 = fvalue; break;
                case "nv9": nv9 = fvalue; break;
                case "nv10": nv10 = fvalue; break;
                case "dt1": dt1 = fvalue; break;
                case "dt2": dt2 = fvalue; break;
                case "dt3": dt3 = fvalue; break;
                case "dt4": dt4 = fvalue; break;
                case "adduser": adduser = fvalue; break;
                case "wfid": wfid = fvalue; break;
                case "fatherid": fatherid = fvalue; break;
                case "modelid": modelid = fvalue; break;
                case "addorgthis": addorgthis = fvalue; break;
                case "addorgmain": addorgmain = fvalue; break;
                case "state": state = fvalue; break;
                default: break;
            }
        }


    }
}
